package com.example.mapper;

import com.example.pojo.User;
import org.apache.ibatis.annotations.*;


@Mapper
public interface UserMapper {

    // 根据用户ID和密码查询用户
    @Select("SELECT * FROM users WHERE userId = #{userId} AND password = #{password}")
    User selectByUserIdAndPassword(@Param("userId") String userId, @Param("password") String password);

    // 根据用户ID查询用户
    @Select("SELECT * FROM users WHERE userId = #{userId}")
    User selectByUserId(@Param("userId") String userId);

    // 插入新用户
    @Insert("INSERT INTO users(userId, password, realName, sex, identityCard, birthday, userType) "
            + "VALUES(#{userId}, #{password}, #{realName}, #{sex}, #{identityCard}, #{birthday}, #{userType})")
    @Options(useGeneratedKeys = true, keyProperty = "userId")
    int insert(User user);

    // 根据用户ID查询性别
    @Select("SELECT sex FROM users WHERE userId = #{userId}")
    Integer getSexByUserId(String userId);

    // 根据用户ID查询用户（同上，似乎是重复定义，可以删除）
    @Select("SELECT * FROM users WHERE userId = #{userId}")
    User selectOrderByUserId(@Param("userId") String userId);
}

